//locked
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int n;
map<string,int> s;
bool check(string s){
	s+='$';
	int tmp=0,cnt=0,lstp=0;
	for(int i=0;i<(int)s.size();i++){
		if('0'<=s[i]&&s[i]<='9'){
			tmp=tmp*10-'0'+s[i];
			if(tmp>1e5) return 0;
		}
		else{
			if(cnt<5&&s[i]=="...:$"[cnt]){
				if(s[lstp]=='.'||s[lstp]==':'||s[lstp]=='$') return 0;
				if(tmp!=0&&(s[lstp]<'1'||'9'<s[lstp])) return 0;
				if(tmp==0&&i-lstp!=1) return 0;
				if(cnt<4&&(tmp<0||255<tmp)) return 0;
				if(cnt==4&&(tmp<0||65535<tmp)) return 0;
				cnt++;
				tmp=0;
				lstp=i+1;
			}else return 0;
		}
	}
	return cnt==5;
}
void solve1(string ad,int i){
	if(check(ad)){
		if(s.count(ad)){
			cout<<"FAIL"<<endl;
		}else{
			cout<<"OK"<<endl;
			s[ad]=i;
		}
	}else{
		cout<<"ERR"<<endl;
	}
}
void solve2(string ad){
	if(check(ad)){
		if(s.count(ad)){
			cout<<s[ad]<<endl;
		}else{
			cout<<"FAIL"<<endl;
		}
	}else{
		cout<<"ERR"<<endl;
	}
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){string op,ad;
		cin>>op>>ad;
		if(op[0]=='S') solve1(ad,i);
		else solve2(ad);
	}
	return 0;
}


